package com.fagertveit.chainsawrus.geom;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;

public class Rectangle extends Shape {
	public float width;
	public float height;
	private float vertices[];
	private float texCoords[];
	
	public Rectangle() {
		super();
		this.width = 1.0f;
		this.height = 1.0f;
	}
	
	public Rectangle(float x, float y, float width, float height) {
		super(x, y);
		this.width = width;
		this.height = height;
	}
	
	public void genVerts() {
		float tempVerts[] = {
			x, y,
			x, y + height,
			x + width, y,
			x + width, y,
			x, y + height,
			x + width, y + height
		};
		
		vertices = tempVerts;
	}
	
	public void genTexCoords() {
		float tempCoords[] = {
			0.0f, 0.0f,
			0.0f, 1.0f,
			1.0f, 0.0f,
			1.0f, 0.0f,
			0.0f, 1.0f,
			1.0f, 1.0f
		};
	}
	
	public void gen3dVerts() {
		float tempVerts[] = {
				x, y, 0,
				x, y + height, 0,
				x + width, y, 0,
				x + width, y, 0,
				x, y + height, 0,
				x + width, y + height, 0
			};
			
			vertices = tempVerts;
	}
	
	public float[] getVerts() {
		return vertices;
	}
	
	public FloatBuffer getBuffer() {
		FloatBuffer buffer = ByteBuffer.allocateDirect(vertices.length * 4)
        .order(ByteOrder.nativeOrder()).asFloatBuffer();
		buffer.put(vertices).position(0);
		
		return buffer;
	}
	
	public FloatBuffer getTexBuffer() {
		FloatBuffer buffer = ByteBuffer.allocateDirect(texCoords.length * 4)
        .order(ByteOrder.nativeOrder()).asFloatBuffer();
		buffer.put(texCoords).position(0);
		
		return buffer;
	}
}
